package com.xlh.server.protocol.support.app;

import com.xlh.bean.ProtocolObject.Window;
import com.xlh.conf.MainHandler;
import com.xlh.interf.IActivity;
import com.xlh.interf.ITakeMessage;
import com.xlh.thread.MessageBagerTask;

/**
 * Created by Created by mike@Q184377367 on 2018/7/2. on 2018/7/2.
 */

public class ReConnectServer implements ITakeMessage {

    private IActivity atv;
    private String hasType = MainHandler.SERVER_CONNECT_ERR;
    private Window protccoObj;
    public ReConnectServer(IActivity atv){
        this.atv = atv;


    }

    @Override
    public void takeMessage(String t,String s){




    }

    @Override
    public boolean takeMessage(String s) {

        ReConnectServer me = this;
        if(!s.equals(MainHandler.SERVER_CONNECT_ERR)) return false;



            this.atv.getActivity().getApp().fixedThreadPool.execute(new MessageBagerTask()
                    .setContext(me.atv.getActivity())
                    .setHandler(me.atv.getActivity().getRenderDataToCenterListHandler())
                    .setData("连接已断开,尝试重连。。。")
                    .setMessageNumber(0) );

            me.atv.getActivity().mSocketClient.stop();


            try {
                Thread.sleep(3000);
                //设定重连
                me.atv.getActivity().setReconnectStatus(true);

                me.atv.getActivity().mSocketClient.start();

            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }




        return true;
    }

    @Override
    public void init() {

    }

    @Override
    public void atViewLoadAfterInit() {

    }








}
